package main

import (
	"webook/internal/repository"
	"webook/internal/repository/cache"
	"webook/internal/repository/dao"
	"webook/internal/service"
	"webook/internal/service/sms"
	"webook/internal/web"

	"github.com/redis/go-redis/v9"
	"gorm.io/gorm"
)

func main() {

	server := InitWebServer()
	server.Run(":8080")
}

func initUser(db *gorm.DB, redisClient redis.Cmdable, smsService sms.Service) (u *web.UserHandler) {
	dao := dao.NewUserDAO(db)
	uc := cache.NewUserCache(redisClient)
	// 由于 *redis.Cmdable 是指针类型，不能直接作为 redis.Cmdable 接口传递，需解引用
	repo := repository.NewUserRepository(dao, uc)
	svc := service.NewUserService(repo)
	codeCache := cache.NewCodeCache(redisClient)
	codeRepo := repository.NewCodeRepository(codeCache)
	codeSvc := service.NewCodeService(codeRepo, smsService)
	return web.NewUserHandler(svc, codeSvc)
}
